
/*******************************************************************************
 * client.hpp - client interface for trasit
 *
 * Copyright (C) 2006 Nathaniel McCallum <nathaniel@natemccallum.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
 ******************************************************************************/

#ifndef __BOQUE_TRASIT_CLIENT_HPP_2010__
#define __BOQUE_TRASIT_CLIENT_HPP_2010__

#include <sys/types.h>

#include <stdexcept>
#include <string>
#include <map>


namespace boque {
namespace trasit {

/*

 This is a class client of data transfer operation working with class sinker.
 Its function is send or buffer data to sinkers somewhere remotely.

 example :

 #include "boque/amsgmanip.hpp"

 // initialize client
 const char*  buf_dir = "/var/trasit/buffered";
 boque::trasit::Client	c( buf_dir );

 // prepare (compose/box) data to send
 int 	id = 1;
 std::string	data( "hello, world" );
 std::string	msg;
 AMsgManip::box( msg, id, data );

 std::string	to( "tcp://127.0.0.1:4331" );
 try {
	 int rc = c.send( to, msg );
	 if ( rc < 0 ) {
		// something is wrong,
		// but, this should never happened
	 }
 }
 catch (std::exception& e) {
 	// see what happens : e.what()
 }

 link libraries :
    libboque_buffesq.a
	libboque_trasit.a

-L/home/s/lib/static
-lboque_trasit -lboque_buffesq -lbocat_logging -lbocat_common 
-lboost_program_options-mt -lboost_filesystem-mt -lboost_system-mt -lboost_thread-mt -lpthread

 */

class Client
{

public:
    Client( const std::string& buf_dir );
    ~Client();

public	:
	int	send( const std::string& to, const std::string& data, bool bufferable=true );
	int	send( const std::string& to, const void* data, const u_int32_t size, bool bufferable=true );
    
private :
    Client( const Client& );
    Client&    operator=( const Client& );

private	:

	typedef	void*	tube_v_ptr;
	typedef	std::map< std::string, tube_v_ptr >	tubes_type;
	typedef	tubes_type::iterator		tube_iterator_type;

private	:
	tube_v_ptr	getTube( const std::string& addr );

private :
	std::string		_buf_dir;

	tubes_type	_tubes;

};	// class Client


}	// namespace trasit
}	// namespace boque


#endif /* __BOQUE_TRASIT_CLIENT_HPP_2010__*/

